FieldServiceDatabase.TestGrid = Ext.extend(Ext.grid.GridPanel, {
    buildTbar: function(){
        var download_button = new Ext.Button({
            xtype: 'button',
            text: 'Download',
            iconCls: 'download-icon'
        });
		
		var report_button = new Ext.Button({
            xtype: 'button',
            text: 'Report',
            iconCls: 'report-icon'
        });
		 
        this.download_button = download_button;
		this.report_button = report_button;
        this.tbar = new Ext.Toolbar({
            items: [download_button, report_button]
        })
    },
    page_size: FieldServiceDatabase.PAGESIZE,
    
    loadMask: true,
    id: 'testgrid-panel',
    
    frame: false,
    //        width: 600,
    height: 600,
    autoScroll: true,
    //        collapsible: true,
    
    animCollapse: false,
    region: 'center',
    
    title: 'Testing List',
    
    store: new Ext.data.JsonStore({
        proxy: new Ext.data.HttpProxy({
            url: '/testings'
        }),
        remoteSort: true
    
    }),
    listener: {
        viewready: function(g){
            g.getSelectionModel().selectFirstRow()
        }
    },
    plugins: new Ext.ux.grid.ColumnHeaderGroup({
        rows: [[{
            header: 'No',
            colspan: 6,
            align: 'center'
        }, {
            header: 'General',
            colspan: 5,
            align: 'center'
        }, {
            header: 'Field Test Data',
            colspan: 3,
            align: 'center'
        }, {
            header: 'Lab Corr. Data',
            colspan: 2,
            align: 'center'
        }, {
            header: 'Control Data',
            colspan: 3,
            align: 'center'
        }, {
            header: 'Compaction',
            colspan: 2,
            align: 'center'
        }, {
            header: 'Results',
            colspan: 1,
            align: 'center'
        }]]
    }),
    columns: [new Ext.grid.RowNumberer(), {
        id: 'id',
        header: "id",
        width: 60,
        sortable: true,
        dataIndex: 'id',
        hidden: true
    }, {
        header: "Client Name",
        width: 50,
        sortable: true,
        dataIndex: 'client_name',
        hidden: true
    
    }, {
        header: "By",
        width: 50,
        sortable: true,
        dataIndex: 'tested_by',
        hidden: true
    
    }, {
        header: "Project Name",
        width: 50,
        sortable: true,
        dataIndex: 'project_name_full',
        hidden: true
    
    }, {
        header: "Project Number",
        width: 50,
        sortable: true,
        dataIndex: 'project_number',
        hidden: true
    
    }, {
        header: "Test No",
        width: 35,
        sortable: true,
        dataIndex: 'test_no',
        hidden: false
    
    },{
        header: "Report Test No",
        width: 35,
        sortable: true,
        dataIndex: 'report_test_no',
        hidden: false
    
    }, {
        header: "Date",
        width: 50,
        sortable: true,
        dataIndex: 'form_date',
        renderer: Ext.util.Format.dateRenderer('m/d/y'),
        hidden: false
    }, {
        header: "Location",
        width: 60,
        sortable: true,
        dataIndex: 'test_location',
        hidden: false
    }, {
        header: "Interval",
        width: 50,
        sortable: true,
        dataIndex: 'test_interval',
        hidden: false
    }, {
        header: "Wet Unit Weight",
        width: 35,
        sortable: true,
        dataIndex: 'wet_unit_weight',
        hidden: false
    }, {
        header: "Moisture Content(%)",
        width: 35,
        sortable: true,
        dataIndex: 'moisture_contentfield',
        hidden: false
    }, {
        header: "Dry Unit Weight(pcf)",
        width: 35,
        sortable: true,
        dataIndex: 'dry_unit_weight',
        hidden: false
    }, {
        header: "Lab MC(%)",
        width: 30,
        sortable: true,
        dataIndex: 'moisture_contentlab',
        hidden: false
    }, {
        header: "Lab DUW(pcf)",
        width: 35,
        sortable: true,
        dataIndex: 'dry_unit_weight_lab',
        hidden: false
    }, {
        header: "Curve No.",
        width: 30,
        sortable: true,
        dataIndex: 'curve_no',
        hidden: false
    }, {
        header: "Max dry unit weight",
        width: 35,
        sortable: true,
        dataIndex: 'max_dry_unit_weight',
        hidden: false
    }, {
        header: "Optium Moisture Content(%)",
        width: 35,
        sortable: true,
        dataIndex: 'optimum_moisture_content',
        hidden: false
    }, {
        header: "Specified(%)",
        width: 30,
        sortable: true,
        dataIndex: 'specified',
        hidden: false
    }, {
        header: "Obtained(%)",
        width: 35,
        sortable: true,
        dataIndex: 'obtained',
        hidden: false
    }, {
        header: "Remarks",
        width: 50,
        sortable: true,
        dataIndex: 'remarks',
        hidden: false
    }],
    viewConfig: {
        forceFit: true
    },
    
    
    initComponent: function(){
        // paging bar on the bottom
        var page_size = this.page_size;
        var store = this.store;
		this.buildTbar();
        this.bbar = new Ext.PagingToolbar({
            pageSize: page_size,
            store: store,
            displayInfo: true,
            displayMsg: 'Displaying topics {0} - {1} of {2}',
            emptyMsg: "No topics to display"
        }), Ext.apply(this, {});
        
        FieldServiceDatabase.TestGrid.superclass.initComponent.call(this, arguments);
        this.getStore().on('exception', function(dp, type, action, options, response){
            Ext.MessageBox.confirm('Error', 'Network Temporarily not available, do you want to try again?', function(btn, text){
                if (btn == 'yes') {
                    this.load({params: options.params})
                }
                else {
                    this.removeAll()
                }
            }, this);
        })
    }
});

Ext.reg('testgrid', FieldServiceDatabase.TestGrid);

